<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="/web/js/global/global_header.js"></script>
    <title>华锐Pms</title>
</head>
<style>
    .el-table--border .el-table__cell:first-child .cell {
        padding-left: 14px;
        overflow: visible !important;
    }
</style>

<body>
    <div id="app" class="bgc-f2 pl-16 pr-16 pt-16" v-cloak>
        <div>
            <div class="ub ub-ac ub-pe mb-16">
                <div>
                    <el-button type="primary" size="small" @click="editClick({})" class="tx-14">添加账号</el-button>
                </div>
            </div>
            <div class="bgc-wh ">
                <el-table :data="tableData" style="width: 100%" border
                    :header-cell-style="{background:'#eaedf4','color':'#333',padding:'8px 0'}" ref="multipleTable">
                    <el-table-column label="分类" width="400">
                        <template slot-scope="scope">
                            <div>
                                {{getDictionary(faeConsumptionType,'id',scope.row.typeId,'name')}}
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="name" label="消费项名称" width="400"></el-table-column>
                    <el-table-column prop="price" label="价格" width="400">
                        <template slot-scope="scope">
                            ￥{{scope.row.price.toFixed(2)}}
                        </template>
                    </el-table-column>
                    <el-table-column label="状态">
                        <template slot-scope="scope">
                            <div class="ub ub-ac">
                                <div class="mr-8">
                                    <el-switch :value="scope.row.status == 1?true:false" active-color="#053dc8"
                                        inactive-color="#ff4949" @change="statusChange(scope.row)">
                                    </el-switch>
                                </div>
                                <div>
                                    <template v-if="scope.row.status == 1">启用</template>
                                    <template v-if="scope.row.status == 0">停用</template>
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column fixed="right" label="操作" width="400">
                        <template slot-scope="scope">
                            <el-button @click="editClick(scope.row)" type="text" size="small" class="tx-14 btn-br">编辑
                            </el-button>
                            <el-button type="text" size="small" class="tx-re tx-14 btn-br" @click="delClick(scope.row)">
                                删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </div>
    </div>
    <script type="text/babel">


        window.vm = new Vue({
            el: '#app',
            data: {
                name: 'zwzhai',
                userCount: 0,
                tableData: [],
                total: 100,
                userinfo: Pms.getDate("userinfo", {}),
                faeConsumptionType: [],
                params: {
                    pageNo: 1,
                    pageSize: 10,
                },
            },
            beforeCreate() {
                top.vm.startLoading("加载中")
            },
            created() {
                this.getOption();
            },
            methods: {
                getOption() {
                    // 获取消费项分类数据
                    this.GET({ url: top.Config.curUrl + "/fae/faeConsumptionType/list" }).then((res) => {
                        if (res.retcode == 200) { //如果返回码不是200则提示错误登录信息
                            this.faeConsumptionType = res.result.faeConsumptionTypeList;
                            // 获取表格数据
                            this.getList();
                        } else { //如果返回码是200则登录成功
                            this.msgError(res.retmsg)
                        }
                    })
                },
                getList() {
                    this.GET({ url: top.Config.curUrl + "/fae/faeConsumptionConfig/list", map: this.params }).then((res) => {
                        if (res.retcode == 200) { //如果返回码不是200则提示错误登录信息
                            this.tableData = res.result.pageInfo.list;
                            this.total = res.result.pageInfo.total;
                        } else { //如果返回码是200则登录成功
                            this.msgError(res.retmsg)
                        }
                        top.vm.closeLoading();
                    })
                },
                //切换分页时触发
                handleCurrentChange(v) {
                    this.params.pageNo = v;
                    this.getList();
                },
                // 选择分页条数时触发
                handleSizeChange(v) {
                    this.params.pageSize = v;
                    this.getList();
                },
                // 编辑按钮
                editClick(row) {
                    this.openDetailsWin({
                        id: "consumption_items_config_edit",
                        params: { id: row.id || "" },
                        iframeUrl: "/web/view/consumption/consumption_items_config_edit.html"
                    })
                },
                // 删除按钮
                delClick(row) {
                    this.confirm("您确认删除吗？").then(() => {
                        let params = JSON.parse(JSON.stringify(row))
                        params.status = -1
                        this.POST({ url: top.Config.curUrl + "/fae/faeConsumptionConfig/save", map: params }).then((res) => {
                            if (res.retcode == 200) { //如果返回码不是200则提示错误登录信息
                                setTimeout(() => {
                                    this.getList();
                                    this.msgSuccess("删除成功");
                                }, 1000);
                            } else { //如果返回码是200则登录成功
                                this.msgError(res.retmsg);
                            }
                        })
                    })
                },
                statusChange(row) {
                    let tipsText = row.status == 1 ? '停用' : '启用'
                    row.status = row.status == 1 ? 0 : 1
                    this.confirm("确认" + tipsText + "吗？").then(() => {
                        this.POST({ url: top.Config.curUrl + "/fae/faeConsumptionConfig/save", map: row }).then((res) => {
                            if (res.retcode == 200) { //如果返回码不是200则提示错误登录信息
                                this.msgSuccess(tipsText + "成功");
                            } else { //如果返回码是200则登录成功
                                row.status = row.status == 1 ? 0 : 1
                                this.msgError(res.retmsg);
                            }
                        })
                    }).catch(() => {
                        row.status = row.status == 1 ? 0 : 1
                    })
                }
            }
        })

    </script>

</body>

</html>